package com.express.ExpInsuranceLog.service;


import com.aqgj.util.JsonWrapper;
import com.express.ExpInsuranceLog.bean.ExpInsuranceLog;
import com.express.ExpInsuranceLog.dao.ExpInsuranceLogDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;


@Service("ExpInsuranceLog")
public class ExpInsuranceLogManager {

    @Autowired
    ExpInsuranceLogDao expInsuranceLogDao;


    public HashMap<String,Object> getInsuranceLogList(Integer pageNo, Integer pageSize) {
        String sql = "SELECT id,exp_release_id," +
                     "CASE WHEN TYPE=1 THEN '收入' WHEN TYPE=2 THEN '支出'  WHEN TYPE=3 THEN '支出' end as type," +
                     "insurance_money,insurance_scale,after_balance,trade_time,remake " +
                     "FROM exp_insurance_log order by trade_time desc ";
        HashMap<String,Object> result= expInsuranceLogDao.listAndSumSqlPagQuery(sql,pageNo,pageSize);
        if((Integer)result.get("sum")>0){
          return JsonWrapper.successPagerWrapper(expInsuranceLogDao.getKeyList((List) result.get("data"),new String[]{"id","orderId","type","insuranceMoney","insuranceScale","afterBalance","tradeTime","remake"}),(Integer)result.get("sum"));
        }
        return JsonWrapper.successWrapper("");
    }

    public void save(ExpInsuranceLog expInsuranceLog) {
        expInsuranceLogDao.save(expInsuranceLog);
    }
}
